package stream;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class Student {
    /**
     * 姓名
     */
    private String name;

    /**
     * 年龄
     */
    private Integer age;

    /**
     * 性别
     */
    private String gender;

    /**
     * 成绩
     */
    private Integer grade;

    public Student(String name, Integer age, String gender, Integer grade) {
        this.name = name;
        this.age = age;
        this.gender = gender;
        this.grade = grade;
    }

    public Integer getAge() {
        return age;
    }

    public String getGender() {
        return gender;
    }
    public Integer getGrade() {
        return grade;
    }
    public String getName() {
        return name;
    }
    public void setAge(Integer age) {
        this.age = age;
    }
    public void setGender(String gender) {
        this.gender = gender;
    }
    public void setGrade(Integer grade) {
        this.grade = grade;
    }
    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        // TODO Auto-generated method stub
        StringBuilder stringBuilder = new StringBuilder();
        String sta = "{";
        String space = ",";
        String end = "}";
        Field[] declaredFields = Student.class.getDeclaredFields();

        stringBuilder.append(sta);
        for(Field field: declaredFields) {
            stringBuilder.append(field.getName()+ "=");
            try {
                stringBuilder.append(field.get(this) + "");
            } catch(IllegalAccessException ie) {
                //
            }
            stringBuilder.append(space);
        }
        stringBuilder.append(end);

        return stringBuilder.toString();
    }
}
